package com.erp.module.yiJianXiang

import android.content.Context
import android.util.Log
import com.erp.Interface.OnUserDataInterface
import com.erp.bean.TouSuSouSuoBean
import com.erp.contacts.Contacts
import com.erp.util.Httputil.*
import com.erp.util.Myutil.dateToStamp
import org.xutils.http.HttpMethod
import org.xutils.http.RequestParams
import org.xutils.x

/**
 * Created by Administrator on 2019/3/20/020.
 * 作者：刘洋
 */
class YiJianXiangModel {
    /**获取投诉建议列表 */
    fun getTouSu(context: Context, page: Int, pagesize: Int, bean: TouSuSouSuoBean, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.TOUSU)
        getparams(context, params)
        addtoken(params)
        setProsess(params)
        params.addBodyParameter("page", page.toString())
        params.addBodyParameter("pagesize", pagesize.toString())
        if (bean.changqu != "") {
            params.addBodyParameter("searchParams[cs_han_qu]", bean.changqu)
        }
        if (bean.gongzuodi != "") {
            params.addBodyParameter("searchParams[shi_ji_gong_zuo_di]", bean.gongzuodi)
        }
        if (bean.bumen != "") {
            params.addBodyParameter("searchParams[cs_bu_men]", bean.bumen)
        }
        if (bean.tousu != "") {
            params.addBodyParameter("searchParams[cs_complaint_mh]", bean.tousu)
        }
        if (bean.jianyi != "") {
            params.addBodyParameter("searchParams[cs_suggestion_mh]", bean.jianyi)
        }
        params.addBodyParameter("searchParams[time_filter][time_category]", "cs.ctime")
        if (bean.starttime != "") {
            params.addBodyParameter("searchParams[time_filter][start_time]", dateToStamp(bean.starttime))
        }
        if (bean.endtime != "") {
            params.addBodyParameter("searchParams[time_filter][end_time]", dateToStamp(bean.endtime))
        }
        //        params.addBodyParameter("searchParams[time_filter][time_category]","cs.ctime");
        //        params.addBodyParameter("searchParams[time_filter][start_time]",Myutil.dateToStamp(bean.starttime));
        //        params.addBodyParameter("searchParams[time_filter][end_time]",Myutil.dateToStamp(bean.endtime));
        Log.d("TAAAG", "pa=$params")
        x.http().get<String>(params, Call(context, onUserDataInterface))
    }

    /**删除投诉建议 */
    fun deleteTouSu(context: Context, id: String, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.TOUSU + "/" + id)
        getparams(context, params)
        addtoken(params)
        x.http().request(HttpMethod.DELETE, params, Call(context, onUserDataInterface))
    }
}